#include "app.h"
#include "W25Qxx.h"
#include "driver_usart.h"
#include "bt24.h"
#include "module_ymodem.h"
#include "device_storage.h"

void app(void)
{
  int32 rev = 0;
  // int32 data_len;
  uint8 buff[256];
  uint32 adress = STORAGE_WORD_STOCK;
  strat_usart_interupt();

  device_storage_init();

  // rev = ymodem_handel(device_storage_continuou_write, STORAGE_WORD_STOCK);
  if (rev == REV_OK) {
		GUA_LOGI("successful\r\n");
    for (int i=0; i<1257; i++) {
      printf("[%d]\r\n", i);
      device_storage_read(adress, buff, 256);
      for (int j=0; j<256; j++) {
        printf("%c", buff[j]);
      }
      printf("\r\n");
      memset(buff, 0, 256);
      adress += 256;
    }
  }

  init_bt24();

  while (1) {
    if(Rx_Flag){  // Receive flag
      Rx_Flag=0;	// clean flag
      HAL_UART_Transmit_DMA(&huart2, Rx_Buf, Rx_Len);
    }

    if(Rx2_Flag){  // Receive flag
      Rx2_Flag=0;	// clean flag
      HAL_UART_Transmit_DMA(&huart1, Rx2_Buf, Rx2_Len);
    }
  }

}
